<template>
  <!-- 机器人日志 -->
  <div class="box-shadow">
    <!-- 搜索 -->
    <div class="search-area">
      <div class="form">
        <el-form
          :model="listQuery"
          ref="listQuery"
          size="small"
          :inline="true"
          label-width="115px"
        >
          <el-form-item prop="startTime" label="时间段:">
            <el-date-picker
              v-model="listQuery.startTime"
              type="datetime"
              placeholder="选择开始时间"
              size="medium"
              format="yyyy-MM-dd HH:mm:ss"
              value-format="yyyy-MM-dd HH:mm:ss"
              default-time="['00:00:00', '23:59:59']"
              :picker-options="pickerOptionsStart"
            >
            </el-date-picker>
          </el-form-item>
          <span
            style="
              color: #fff;
              margin-right: 10px;
              display: inline-block;
              height: 36px;
              line-height: 36px;
            "
            >—</span
          >
          <el-form-item prop="endTime">
            <el-date-picker
              v-model="listQuery.endTime"
              type="datetime"
              placeholder="选择结束时间"
              size="medium"
              format="yyyy-MM-dd HH:mm:ss"
              value-format="yyyy-MM-dd HH:mm:ss"
              default-time="['00:00:00', '23:59:59']"
              :picker-options="pickerOptionsEnd"
            >
            </el-date-picker>
          </el-form-item>
          <!-- <el-form-item label="时间段:">
            <el-input
              v-model="listQuery.startTime"
              placeholder="请输入"
              clearable
              size="medium"
            />
          </el-form-item>
          <span
            style="
              color: #fff;
              margin-right: 10px;
              display: inline-block;
              height: 36px;
              line-height: 36px;
            "
            >—</span
          >
          <el-form-item>
            <el-input
              v-model="listQuery.endTime"
              placeholder="请输入"
              clearable
              size="medium"
            />
          </el-form-item> -->
          <el-form-item label="日志描述:">
            <el-input
              v-model="listQuery.operContent"
              placeholder="请输入"
              clearable
              size="medium"
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
        </el-form>
      </div>
      <div class="search-area-btn btns">
        <div @click="serachBtn" class="serch-btn cuver-point">搜索</div>
        <div @click="resetFormBtn('listQuery')" class="reset-btn cuver-point">
          重置
        </div>
      </div>
    </div>
    <!-- 表格 -->
    <div class="table">
      <div class="self">
        <div class="search-area-btn btns">
          <div class="serch-btn cuver-point table-top" @click="handelExit">
            导出
          </div>
        </div>
        <div class="tooltips">
          <span>提示：由于操作日志数据过多，系统自动清理3个月之前的数据</span>
        </div>
        <el-table
          ref="tableRef"
          :data="tableData"
          tooltip-effect="dark"
          style="width: 100%; margin-top: 16px"
          @selection-change="selectionChange"
        >
          <el-table-column type="selection" width="55"> </el-table-column>
          <el-table-column width="100" align="center" prop="id" label="日志ID">
          </el-table-column>
          <el-table-column
            width="200"
            align="center"
            prop="createTime"
            label="创建时间"
          >
          </el-table-column>
          <el-table-column align="center" prop="operContent" label="日志描述">
          </el-table-column>
        </el-table>
      </div>
      <div class="pagenation">
        <pagination
          :total="total"
          :limit.sync="listQuerySubmit.pageSize"
          @pagination="getTableList"
        >
        </pagination>
      </div>
    </div>
  </div>
</template>
<script>
import { API_getSearch } from "@/api/log/robotlog";
export default {
  data() {
    return {
      // 结束日期
      pickerOptionsEnd: {
        disabledDate: (time) => {
          let beginDateVal = this.listQuery.startTime;
          if (beginDateVal) {
            return (
              time.getTime() <
              new Date(beginDateVal).getTime() + 1 * 24 * 60 * 60 * 1000
            );
          }
        },
      },
      pickerOptionsStart: {
        disabledDate: (time) => {
          let endDateVal = this.listQuery.endTime;
          if (endDateVal) {
            return (
              time.getTime() >=
              new Date(endDateVal).getTime() + 1 * 24 * 60 * 60 * 1000
            );
          }
        },
      },
      listQuery: {
        startTime: "",
        endTime: "",
        operContent: "",
      },
      total: 0,
      listQuerySubmit: {},
      tableData: [], //表格数据
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
    };
  },
  created() {
    this.listQuerySubmit = Object.assign({}, this.listQuery);
    this.getTableList();
  },
  mounted() {},
  methods: {
    /** 重置按钮操作 */
    resetFormBtn() {
      this.listQuery = {
        startTime: "",
        endTime: "",
        operContent: "",
      };
      this.serachBtn();
    },
    /**搜索 */
    serachBtn() {
      // this.listQuery.pageNum = 1;
      this.listQuerySubmit = Object.assign({}, this.listQuery);
      this.getTableList();
    },
    /** table多选 */
    selectionChange(selection) {
      this.ids = selection.map((item) => item.resourceId);
      this.single = selection.length !== 1;
    },

    /**表格数据 */
    getTableList() {
      API_getSearch(this.listQuery).then((response) => {
        this.tableData = response.rows;
      });
    },
    // 导出
    handelExit() {
      console.log("123");
    },
  },
};
</script>
<style lang="scss" scoped>
.table {
  width: 100%;
  height: 738px;
  border-top: 1px dashed rgba(219, 255, 251, 0.2);
  padding: 24px;
  box-sizing: border-box;
  .btns {
    display: flex;
    width: 100%;
    justify-content: flex-start;
    div:nth-child(2) {
      margin: 0 16px;
    }
  }
  .table-btns {
    display: flex;
    div {
      display: flex;
      width: 46px;
      height: 28px;
      justify-content: center;
      align-items: center;
      font-size: 12px;
    }
    div:nth-child(2) {
      margin: 0 10px;
    }
  }
  .tooltips {
    width: 100%;
    height: 40px;
    line-height: 40px;
    padding-left: 16px;
    background: #0f1a23;
    margin: 24px 0 16px 0;
    span {
      display: block;
      font-size: 14px;
      color: #ffad30;
    }
  }
}
::v-deep {
  .el-form-item__content {
    width: 220px;
  }
}
</style>
